package util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
    public static String dateToString19Char(Date date){
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }
    public static String dateToString10Char(Date date){
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(date);
    }
    public static Date stringToDate(String time) throws Exception {
        SimpleDateFormat sdf=null;
        if(time.length()==10){
            sdf=new SimpleDateFormat("yyyy-MM-dd");
        }else {
            sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        }
        Date data=sdf.parse(time);
        return data;
    }
}
